<?php
/**
 * 更新选项
 */
function ibapithemeset_update_options($options){
    update_option('ibapithemeset_options', $options);
}

/**
 * 在插件下方放置“设置”链接
 */


/**
 * 添加菜单
 */
function ibapithemeset_add_setting_page() {
    add_options_page('爱扒皮主题设置器', '爱扒皮主题设置器', 8, __FILE__, 'ibapithemeset_setting_page');
}

/**
 * 菜单页面
 */
function ibapithemeset_setting_page() {
    if( $_POST['ibapithemeset_submit_hidden'] === 'yes' ) { //如果确定更新，给出更新的提示
        $options['theme_keywords'] = stripslashes(apply_filters('ibapithemeset_message', $_POST['ibapithemeset_theme_keywords']));
        $options['theme_descriptions'] = stripslashes(apply_filters('ibapithemeset_message', $_POST['ibapithemeset_theme_descriptions']));
        $options['theme_contentlimit'] = stripslashes(apply_filters('ibapithemeset_message', $_POST['ibapithemeset_theme_contentlimit']));
        $_POST['active_plugin'] === 'true'
             ? $options['active_plugin'] = 'true'
             : $options['active_plugin'] = 'false';
      //  $_POST['slug_plugin'] === 'true'
        //     ? $options['slug_plugin'] = 'true'
          //   : $options['slug_plugin'] = 'false';
        ibapithemeset_update_options($options);
        
?>
<div class="updated"><p><strong>设置已保存！</strong></p></div>
<?php
    }
    $ibapithemeset_options = ibapithemeset_get_options();
    $ibapithemeset_theme_keywords = $ibapithemeset_options['theme_keywords'];
    $ibapithemeset_theme_descriptions = $ibapithemeset_options['theme_descriptions'];
    $ibapithemeset_theme_contentlimit = $ibapithemeset_options['theme_contentlimit'];
?>
<div class="wrap">
    <h3>爱扒皮 主题设置器</h3>
    <form name="form1" method="post" action="<?php echo wp_nonce_url('./options-general.php?page=' . IBAPITHEMESET_BASEFOLDER . '/ibapithemeset-admin.php'); ?>">
        <div style="font-size:18px;">设置 SEO优化（请检查主题的Header.php中是否有do_action('wp_head')函数）</div><hr />
        <input type="hidden" name="ibapithemeset_submit_hidden" value="yes">
        <fieldset style="margin: 10px;">
            <legend>是否使用SEO优化功能：</legend>
            <input type="checkbox" name="active_plugin" id="active_plugin" <?php if ($ibapithemeset_options['active_plugin'] == 'true') echo 'checked="checked"';?> value="true" />
            <label for="active_plugin">使用SEO优化功能</label>
        </fieldset>
          <!--  <fieldset style="margin: 10px;">
            <legend>是否使用SLUG TRANSLATE功能：</legend> <?php echo $ibapithemeset_options['slug_plugin'] ?>
            <input type="checkbox" name="slug_plugin" id="slug_plugin" <?php if ($ibapithemeset_options['slug_plugin'] == 'true') echo 'checked="checked"';?> value="true" />
            <label for="slug_plugin">使用SLUG TRANSLATE优化功能</label>
        </fieldset> -->
        <fieldset style="margin: 10px;">
            <legend>在此填写博客关键字(以半角逗号","分隔)：</legend>
            <input name="ibapithemeset_theme_keywords" value="<?php echo $ibapithemeset_theme_keywords; ?>"  size="100" id="ibapithemeset_theme_keywprds" class="ibapithemeset_setting">
        </fieldset>
        <fieldset style="margin: 10px;">
            <legend>在此填写博客描述：</legend>
            <input name="ibapithemeset_theme_descriptions" value="<?php echo $ibapithemeset_theme_descriptions; ?>"  size="100" id="ibapithemeset_theme_descriptions" class="ibapithemeset_setting">
        </fieldset>
        <fieldset style="margin: 10px;">
            <legend>描述字数控制（默认110）：</legend>
            <legend>本功能用于分页（Single.php），对首页无效。作用在于选取一定字数的文章作为该页的Description，默认为110，不建议增加长度。</legend>

            <input name="ibapithemeset_theme_contentlimit" value="<?php echo $ibapithemeset_theme_contentlimit; ?>"  size="3" maxlength="3" id="ibapithemeset_theme_contentlimit" class="ibapithemeset_setting">
        </fieldset>
        <div style="font-size:18px;">设置 自定义版权区域</div><hr />
        该功能正在开发中……
        <fieldset class="submit" style="margin: 10px;">
            <legend>更新选项</legend>
            <input type="submit" name="Submit" value="更新" />
        </fieldset>
    </form>
</div>
<?php
}
?>